package messages;

import java.io.Serializable;


/**
 * Message class.
 * 
 * Message is the standard communication mechanism used both by the
 * servers and by the clients to communicate with each other. 
 * 
 * This is only an abstract class. There are derived classes for each
 * kind of message specified by the communication-protocol.
 */
public abstract class Message implements Serializable, Cloneable {
	
	
	/**
	 * Returns the message ID.
	 * 
	 * @return The message ID.
	 */
	public int getId() {
		return id;
	}
	
	
	public void setId(int id) {
		this.id = id;
	}
	
	
	/**
	 * Returns the ID of the last message the sender received.
	 * 
	 * @return The ID of the last message the sender received.
	 */
	public int getLastReceivedId() {
		return lastReceivedId;
	}
	
	
	public void setLastReceivedId(int lastReceivedId) {
		this.lastReceivedId = lastReceivedId;
	}
	
	
	@Override
	public String toString() {
		return "MSG[" + id + "/" + lastReceivedId + "] " + this.getClass().getSimpleName();
	}
	
	
	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	
	private int id;			    // This is a growing-identifier assigned by the Sender (whether its the server or the client) 
	private int lastReceivedId;	// This is the identifier of the last message that the Sender received

	private static final long serialVersionUID = 2485895607929234819L;
}
